package src.cn.edu.sdjzu.xg.eagle.fastjon;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.IOException;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        // 从文件中读取JSON字串
        String json_obj_str = TxtHelper.readTxt("files/" + "paginationObject.txt");
        // 将JSON字串解析为JSONObject对象
        JSONObject pagination_json_obj = JSON.parseObject(json_obj_str);
        // 根据键来获得值
        Object pageSize_obj = pagination_json_obj.get("pageSize");
        Object pageNo_obj = pagination_json_obj.get("pageNo");
        // 将JSON字串直接转换为Java对象。
        Pagination pagination2 = JSON.parseObject(json_obj_str, Pagination.class);
        int pageNo2 = pagination2.getPageNo();
        int pageSize2 = pagination2.getPageSize();
        System.out.println(pageNo2);
        System.out.println(pageSize2);

        String json_array_str = TxtHelper.readTxt("files/" + "conditionArray.txt");
        // 将JSON字串直接转换为Java的List对象
        List<Condition> conditionList = JSON.parseArray(json_array_str, Condition.class);
        System.out.println(conditionList);
        // 将JSON字串转换为JSONArray对象
        JSONArray json_array_obj = JSON.parseArray(json_array_str);
        System.out.println(json_array_obj);
    }
}